//
//  HWScreeningView.m
//  HWanGame
//
//  Created by 陈道斌 on 2019/9/2.
//  Copyright © 2019 Chendaobin. All rights reserved.
//

#import "HWScreeningView.h"

@interface HWScreeningView()
@property(strong,nonatomic) UIView *grayView;
@property(strong,nonatomic) UIView *whiteView;
@property(strong,nonatomic) UITextField *nameTextField;
@property(strong,nonatomic) UITextField *minimumTextField;
@property(strong,nonatomic) UITextField *highestTextField;


@end

@implementation HWScreeningView

- (instancetype)initWithFrame:(CGRect)frame  {
    
    if (self  = [super initWithFrame:frame]) {
        // 添加灰色背景
        [self addgrayView];
        
        [self setupUI];
        
        
    }
    return  self;
    
}


//  设置UI
- (void)setupUI {

   
    self.whiteView = [[UIView alloc]init];
    self.whiteView.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.whiteView];
    
    UIView *fengexianView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, 1)];
    fengexianView.backgroundColor = RGB(215, 215, 215);
  //  fengexianView.backgroundColor = [UIColor orangeColor];
    [self.whiteView addSubview:fengexianView];
    
    UILabel *guanjiaziLabel = [[UILabel alloc]initWithFrame:CGRectMake(17, 7, 101-17, 36)];
    guanjiaziLabel.font  = [UIFont systemFontOfSize:12];
    guanjiaziLabel.text = @"关键词";
    guanjiaziLabel.textColor = RGB(51, 51, 51);
    
    [self.whiteView addSubview:guanjiaziLabel];
    
    UITextField *goodsTextField = [[UITextField alloc]initWithFrame:CGRectMake(101, 10, 169,29)];
    goodsTextField.placeholder = @"可查找商品标题";
    goodsTextField.font = [UIFont systemFontOfSize:12];
    goodsTextField.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 13, 29)];
    goodsTextField.leftViewMode = UITextFieldViewModeAlways;
    goodsTextField.backgroundColor =RGB(245, 245, 245);
    goodsTextField.textColor = RGB(51, 51, 51);
    goodsTextField.layer.cornerRadius = 5;
    goodsTextField.layer.masksToBounds = YES;
    goodsTextField.text = @"";
    self.nameTextField = goodsTextField;
    NSMutableAttributedString *attrString3 = [[NSMutableAttributedString alloc] initWithString:@"可查找商品标题" attributes:
          @{NSForegroundColorAttributeName:RGB(215, 215, 215),
            NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}
          ];
    goodsTextField.attributedPlaceholder = attrString3;
    [self.whiteView addSubview:goodsTextField];
    
    
    UILabel *qujianLabel = [[UILabel alloc]initWithFrame:CGRectMake(17, guanjiaziLabel.bottom, 101-17, 36)];
    qujianLabel.font  = [UIFont systemFontOfSize:12];
    qujianLabel.text = @" 价格区间(元)";

    qujianLabel.textColor = RGB(51, 51, 51);
    [self.whiteView addSubview:qujianLabel];
    
    
    UITextField *zuidiTexfiele = [[UITextField alloc]initWithFrame:CGRectMake(101, guanjiaziLabel.bottom+4, 90,29)];
    zuidiTexfiele.placeholder = @"最低价";
    zuidiTexfiele.font = [UIFont systemFontOfSize:12];
    zuidiTexfiele.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 13, 29)];
    zuidiTexfiele.leftViewMode = UITextFieldViewModeAlways;
    zuidiTexfiele.backgroundColor =RGB(245, 245, 245);
    zuidiTexfiele.textColor = RGB(51, 51, 51);
    zuidiTexfiele.layer.cornerRadius = 5;
    zuidiTexfiele.keyboardType   = UIKeyboardTypeNumberPad;
    zuidiTexfiele.layer.masksToBounds = YES;
    zuidiTexfiele.text = @"";
    self.minimumTextField = zuidiTexfiele;
    

      NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:@"最低价" attributes:
         @{NSForegroundColorAttributeName:RGB(215, 215, 215),
           NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}
         ];
     zuidiTexfiele.attributedPlaceholder = attrString;
   
    
    
    [self.whiteView addSubview:zuidiTexfiele];
    
    UIView *henxianview =  [[UIView alloc]initWithFrame:CGRectMake(zuidiTexfiele.right+4, guanjiaziLabel.bottom+18, 8, 1)];
    henxianview.backgroundColor = RGB(51, 51, 51);
    [self.whiteView addSubview:henxianview];
    
    
    UITextField *gaoTexfiele = [[UITextField alloc]initWithFrame:CGRectMake(zuidiTexfiele.right+16, guanjiaziLabel.bottom+4, 90,29)];
    gaoTexfiele.placeholder = @"最高价";
    gaoTexfiele.font = [UIFont systemFontOfSize:12];
    gaoTexfiele.leftView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 13, 29)];
    gaoTexfiele.leftViewMode = UITextFieldViewModeAlways;
    gaoTexfiele.backgroundColor =RGB(245, 245, 245);
    gaoTexfiele.textColor = RGB(51, 51, 51);
    gaoTexfiele.layer.cornerRadius = 5;
    gaoTexfiele.layer.masksToBounds = YES;
    gaoTexfiele.keyboardType   = UIKeyboardTypeNumberPad;
    gaoTexfiele.text = @"";
    self.highestTextField = gaoTexfiele;
    NSMutableAttributedString *attrString1 = [[NSMutableAttributedString alloc] initWithString:@"最高价" attributes:
           @{NSForegroundColorAttributeName:RGB(215, 215, 215),
             NSFontAttributeName:[UIFont boldSystemFontOfSize:12]}
           ];
    gaoTexfiele.attributedPlaceholder = attrString1;
    
    
    [self.whiteView addSubview:gaoTexfiele];
    
    //  全部分类
    UIButton *chongzhiBut = [UIButton buttonWithType:UIButtonTypeCustom];
    chongzhiBut.frame =   CGRectMake(0, 120-35, kScreenW/3, 35);
    chongzhiBut.backgroundColor = RGB(239, 236, 239);
    [chongzhiBut setTitleColor:RGB(102, 102, 102) forState:UIControlStateNormal];
    [chongzhiBut setTitle:@"重置" forState:UIControlStateNormal];
    chongzhiBut.titleLabel.font = [UIFont systemFontOfSize:12];
    [chongzhiBut addTarget:self action:@selector(chongtap) forControlEvents:UIControlEventTouchUpInside];
    
    [self.whiteView addSubview:chongzhiBut];
    
    
    UIButton *determineBut = [UIButton buttonWithType:UIButtonTypeCustom];
    determineBut.frame =   CGRectMake(kScreenW/3, 120-35, kScreenW/3*2, 35);
    determineBut.backgroundColor = RGB(54,147,253);
    [determineBut setTitleColor:RGB(255, 255, 255) forState:UIControlStateNormal];
    [determineBut setTitle:@"确定" forState:UIControlStateNormal];
    determineBut.titleLabel.font = [UIFont systemFontOfSize:12];
    [determineBut addTarget:self action:@selector(queding) forControlEvents:UIControlEventTouchUpInside];
    [self.whiteView addSubview:determineBut];
    
    
    
    
    
    

    
    
    
    
    
    
    
    
}
- (void)relayoutTheChildControls {
    // self.whiteView.backgroundColor = [UIColor redColor];
    self.whiteView.frame = CGRectMake(0, self.whibackvieY, kScreenW, 120);
    self.grayView.frame = CGRectMake(0, self.whibackvieY+120, kScreenW, kScreenH-self.whibackvieY-118+10);
    
 
    
    
}
 





// 添加灰色View
-(void)addgrayView {
    
    self.grayView = [[UIView alloc]init];
    self.grayView.frame  = CGRectMake(0,300, 400, 400);
    
    self.grayView.backgroundColor =  RGB(51, 51, 51);
    self.grayView.alpha = 0.6;
    [self addSubview:self.grayView];
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapView:)];
    //  tap.delegate = self;
    [self.grayView addGestureRecognizer:tap];
    
    
    
    
}

- (void)tapView:(UITapGestureRecognizer *)touch {
    
    [touch.view.superview removeFromSuperview];
    //   [[NSNotificationCenter defaultCenter] postNotificationName:@"notifyName1" object:nil];
    
    
}


#pragma mark --------   点击一些按钮操作
// 点击重置按钮
- (void)chongtap {
    
    DLog(@"重置按钮");
    
    self.nameTextField.text = @"";
    self.minimumTextField.text = @"";
    self.highestTextField.text = @"";
    
    NSDictionary *dic = @{@"keysub":@"",@"zuidiStr":@"",@"zuigaoStr":@""};
    [self.delegate HWScreeningViewDic:dic];
     [self removeFromSuperview];
    
}

// 点击确定按钮

- (void)queding {
    
    
    DLog(@"确定");
    
    NSString *zuidiStr = self.minimumTextField.text;
      NSString *zuigaoStr = self.highestTextField.text;
      CGFloat  di = [zuidiStr floatValue];
      CGFloat gao = [zuigaoStr floatValue];
      
//      if (!(self.nameTextField.text.length > 0)) {
//
//           [MBProgressHUD showError:@"关键子不能为空"];
//            return;
//
//      } else if (!(self.minimumTextField.text.length > 0)) {
//
//             [MBProgressHUD showError:@"最底价不能为空"];
//             return;
//
//      }else if (!(self.highestTextField.text.length > 0)) {
//
//           [MBProgressHUD showError:@"最高价不能为空"];
//           return;
//
//
//      } else if (!(gao > di)) {
//
//          [MBProgressHUD showError:@"最高价不能小于最低价"];
//           return;
//
//
//      }
//
//
    
     NSDictionary *dic = @{@"keysub":self.nameTextField.text,@"zuidiStr":zuidiStr,@"zuigaoStr":zuigaoStr};
     [self.delegate HWScreeningViewDic:dic];
     [self removeFromSuperview];
    
    
    
}




//-(BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch {
//
//    if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
//
//        return NO;
//    }else if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableView"]) {
//
//
//        return NO;
//    }
//    return YES;
//
//
//}




@end
